package com.lanchetech.service.impl;


import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.AreaVO;
import com.lanchetech.common.enums.AreaLevelEnum;
import com.lanchetech.dao.AreaMapper;
import com.lanchetech.dao.StreetMapper;
import com.lanchetech.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AreaServiceImpl implements AreaService {

    @Autowired
    AreaMapper areaMapper;

    @Autowired
    StreetMapper streetMapper;

    @Override
    public ResultData<List<AreaVO>> getAreaList(Integer level, Long pid) {
        if(AreaLevelEnum.STREET.getLevel().equals(level)){
            // 街道
            return new ResultData<>(streetMapper.findAllByArea(pid));
        }
        // 省市区
        return new ResultData<>(areaMapper.findAllByParentIdAndLevelType(pid, level));
    }
}